package cn.vin.demo;

import com.alibaba.fastjson.JSONObject;

public class SortDemo {
    public static void main(String[] args) {
        int[] numbers = new int[]{8,11,10,9,6};
        quickSort(numbers,0,numbers.length-1);
        System.out.println(JSONObject.toJSONString(numbers));
    }
    public static void quickSort(int[] numbers, int start, int end) {

        System.out.println("------------------");
        if (start < end) {
            int base = numbers[start]; // 选定的基准值（第一个数值作为基准值）
            int temp; // 记录临时中间值
            int i = start, j = end;
            do {
                while ((numbers[i] < base) && (i < end))
                    i++;
                while ((numbers[j] > base) && (j > start))
                    j--;
                    System.out.println("i:"+i +", j:" + j);
                if (i <= j) {
                    temp = numbers[i];
                    numbers[i] = numbers[j];
                    numbers[j] = temp;
                    i++;
                    j--;
                    System.out.println(JSONObject.toJSONString(numbers));
                }
            } while (i <= j);
            if (start < j)
                quickSort(numbers, start, j);
            if (end > i)
                quickSort(numbers, i, end);
        }
    }
}
